package com.hckjsec.system.controller;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.hckjsec.common.utils.DateUtils;
import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.system.domain.SysMembershipCost;
import com.hckjsec.system.service.ISysMembershipCostService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 会费缴纳Controller
 * 
 * @author cyt
 * @date 2021-10-12
 */
@RestController
@RequestMapping("/system/sysMembershipCost")
public class SysMembershipCostController extends BaseController
{
    @Autowired
    private ISysMembershipCostService sysMembershipCostService;

    /**
     * 查询会费缴纳列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysMembershipCost sysMembershipCost)
    {
        startPage();
        List<SysMembershipCost> list = sysMembershipCostService.selectSysMembershipCostList(sysMembershipCost);
        return getDataTable(list);
    }

    /**
     * 导出会费缴纳列表
     */
    @Log(title = "会费缴纳", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysMembershipCost sysMembershipCost)
    {
        List<SysMembershipCost> list = sysMembershipCostService.selectSysMembershipCostList(sysMembershipCost);
        ExcelUtil<SysMembershipCost> util = new ExcelUtil<SysMembershipCost>(SysMembershipCost.class);
        return util.exportExcel(list, "cost");
    }

    /**
     * 获取会费缴纳详细信息
     */
    @GetMapping(value = "/{membershipId}")
    public AjaxResult getInfo(@PathVariable("membershipId") Long membershipId)
    {
        return AjaxResult.success(sysMembershipCostService.selectSysMembershipCostById(membershipId));
    }

    /**
     * 新增会费缴纳
     */
    @Log(title = "会费缴纳", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMembershipCost sysMembershipCost)
    {
        sysMembershipCost.setDeptId(SecurityUtils.getDeptId());
        sysMembershipCost.setOperator(SecurityUtils.getUserId());
        return toAjax(sysMembershipCostService.insertSysMembershipCost(sysMembershipCost));
    }

    /**
     * 修改会费缴纳
     */
    @Log(title = "会费缴纳", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMembershipCost sysMembershipCost)
    {
        return toAjax(sysMembershipCostService.updateSysMembershipCost(sysMembershipCost));
    }

    /**
     * 删除会费缴纳
     */
    @Log(title = "会费缴纳", businessType = BusinessType.DELETE)
	@DeleteMapping("/{membershipIds}")
    public AjaxResult remove(@PathVariable Long[] membershipIds)
    {
        return toAjax(sysMembershipCostService.deleteSysMembershipCostByIds(membershipIds));
    }


    //年度列表
    @GetMapping(value = "/getYearList")
    public AjaxResult getYearList()
    {
        List<String>  yearlist = DateUtils.getPastYearList(6);
        //Collections.sort(yearlist);
        yearlist.sort(Comparator.reverseOrder());
        return AjaxResult.success(yearlist);
    }
}
